/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.sgf.api.entity;

import com.inspur.edp.lcm.metadata.api.AbstractMetadataContent;
import com.inspur.edp.sgf.api.utils.ObjectMapperUtil;

import java.text.MessageFormat;
import java.util.ArrayList;

/**
 * 外部服务实体类
 */
public class SgMetadata extends AbstractMetadataContent {

    private String id;

    private String code;

    private String name;

    private String version;

    private String description;

    private String bizObject;

    private String criticalApplication;

    private String serviceUnit;

    private String routeUrl;

    private ServiceDefine service;

    private ArrayList<SgModel> models;

    public SgMetadata() {
        this.service = new ServiceDefine();
        this.models = new ArrayList<>();
    }

    public String getRouter() {
        String router =
                MessageFormat.format(
                        "/api/{0}/{1}/v{2}/{3}",
                        this.getCriticalApplication(),
                        this.getServiceUnit(),
                        this.getVersion(),
                        this.getRouteUrl());
        return router.toLowerCase();
    }

    public String getEndPoint() {
        String endPoint =
                MessageFormat.format(
                        "/{0}/{1}/v{2}/{3}",
                        this.getCriticalApplication(),
                        this.getServiceUnit(),
                        this.getVersion(),
                        this.getRouteUrl());
        return endPoint.toLowerCase();
    }

    @Override
    public Object clone() {
        return ObjectMapperUtil.deserialize(ObjectMapperUtil.serialize(this), SgMetadata.class);
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public void setCode(String code) {
        this.code = code;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public void setName(String name) {
        this.name = name;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getBizObject() {
        return bizObject;
    }

    public void setBizObject(String bizObject) {
        this.bizObject = bizObject;
    }

    public String getCriticalApplication() {
        return criticalApplication;
    }

    public void setCriticalApplication(String criticalApplication) {
        this.criticalApplication = criticalApplication;
    }

    public String getServiceUnit() {
        return serviceUnit;
    }

    public void setServiceUnit(String serviceUnit) {
        this.serviceUnit = serviceUnit;
    }

    public String getRouteUrl() {
        return routeUrl;
    }

    public void setRouteUrl(String routeUrl) {
        this.routeUrl = routeUrl;
    }

    public ServiceDefine getService() {
        return service;
    }

    public void setService(ServiceDefine service) {
        this.service = service;
    }

    public ArrayList<SgModel> getModels() {
        return models;
    }

    public void setModels(ArrayList<SgModel> models) {
        this.models = models;
    }
}
